
def loopDir(){
   // Groovy_遍历文件目录 ： https://blog.csdn.net/rainyrs/article/details/53157328
   def dir = new File("D:\\Project\\SoapUI\\Project-smoke-tests")
   dir.eachDir{directory ->
      println directory
   }
   dir.eachDirMatch(~/^Sanity.*/){d ->
      println d
   }
   dir.eachDirRecurse{directory->
      println directory
   }
}
def loopFile(){
   
   // Groovy_遍历文件 : https://blog.csdn.net/rainyRs/article/details/53184805
   def dir = new File("D:\\data\\appdatas\\cat")
   dir.eachFile(groovy.io.FileType.FILES, {file -> 
         println file.name
         println file.path
      })
   print this
   //dir.eachFileMatch(~/^Sanity.*/){file ->
   //         println file
   //     }
    
}



def deleteFile(){
   new File("d:/_devops/meta-info.md").delete()
}

def checkExists(){
   println new File("d:/_devops/meta-info.md").exists()
}

def readFile(){
   // https://www.cnblogs.com/alansheng/p/4788237.html 读取文件内容
   lineList = new File("D:\\data\\appdatas\\cat\\client.xml").readLines()
   println lineList
}

def writeFile() {  
   def fileName = "C:/Users/LQ/Desktop/Data1.txt"

    def file = new File(fileName)  
      
    if (file.exists())   
        file.delete()  
          
    def printWriter = file.newPrintWriter() //   
      
    printWriter.write('The first content of file')  
    printWriter.write('\n')  
    printWriter.write('The first content of file')  
      
    printWriter.flush()  
    printWriter.close() 
}

def writeFile2(){
   // 文件位置
   def filePath = "C:/Users/LQ/Desktop/Data1.txt"
   new File(filePath).withPrintWriter { printWriter ->  
      printWriter.println('The first content of file')  
   }  

}

// loopFile()

//readFile()

//writeFile();
writeFile2();





